package com.xiaohudie.JUC;

import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @Author xiao hu die
 * @Date 2022/1/15 20:42
 * @Version 1.0
 */
public class Thread12 {
    public static void main(String[] args) {
        Integer a =1;
        ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
        ReentrantReadWriteLock.ReadLock readLock = reentrantReadWriteLock.readLock();
        ReentrantReadWriteLock.WriteLock writeLock = reentrantReadWriteLock.writeLock();
        readLock.lock();
        Integer add = add(a);
        System.out.println(add);
        readLock.unlock();
        writeLock.lock();
        Integer delete = delete(add);
        System.out.println(delete);

    }
    public static Integer add(Integer integer){
        integer ++;
        return integer;
    }
    public static Integer delete(Integer integer){
        integer--;
        return integer;
    }
}
